﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Firearms.dal
{
    public class HexAndByteArr
    {
        public static string byteArr2hexString(byte[] data, int offset)
        {
            StringBuilder ret = new StringBuilder();
            foreach (byte b in data)
            {
                //{0:X2} 大写
                ret.AppendFormat("{0:x2}", b);
            }
            var hex = ret.ToString().ToUpper();
            return hex;
        }
        public static byte[] hexString2byteArr(string data)
        {
            data = data.Replace(" ", "");
            if ((data.Length % 2) != 0) data += " ";
            byte[] returnBytes = new byte[data.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(data.Substring(i * 2, 2), 16);
            return returnBytes;
        }
    }
}
